package com.starblink.frame.base.adapter

import android.annotation.SuppressLint
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.Adapter

abstract class BaseAdapter<VH : BaseVH<*>>(var list: List<Any>) : Adapter<VH>() {

    var parent: ViewGroup? = null

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        this.parent = parent
        return onCreateVH(parent, viewType = viewType, flag = 0)
    }

    abstract fun onCreateVH(
        parent: ViewGroup, viewType: Int, flag: Int = 0
    ): VH

    override fun onBindViewHolder(holder: VH, position: Int) {
        (holder as? BaseVH<Any>)?.onBind(list[position], position)
    }

    override fun getItemCount(): Int = list.size

    @SuppressLint("NotifyDataSetChanged")
    fun refreshAll() = notifyDataSetChanged()


//    fun removeCustomItem(position: Int, positionStart: Int? = null) {
//        notifyItemRemoved(position)
//        if (position < itemCount) {
//            notifyItemRangeChanged(positionStart ?: position, itemCount - position)
//        }
//    }

}